import axios from 'axios'

const state = {
  inspectItemTrees: {
    live: [],
    playback: [],
    camera: []
  },
  inspectCategories: [],
}

const mutations = {
  setInspectItems(state, payload) {
    state.inspectItemTrees = payload;
    let inspectCategories = [];
    for (let i = 0; i < payload.live.length; i++) {
      inspectCategories.push(payload.live[i].title)
    }
    state.inspectCategories = inspectCategories;
  },
}

const actions = {
  loadInspectItems({ commit, rootGetters }) {
    axios.post("api/load_params/", {
      user: rootGetters.userbase,
      params: ['inspectItems']
    }).then(response => {
      if (response.data.status === 0) {
        commit("setInspectItems", response.data.params.inspectItems);
      }
      else {
        console.log(response.data)
      }
    }).catch(exception => {
      console.log(exception)
    });
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}